<?php include "./pc/view/header.inc.htm"; ?>
<div class="container">
    <div class="content" style="width: 770px">
        <div class="content-header" pid="<?php echo $first['pid']; ?>" id="firstpost">
            <div class="tw-header-inner">
                <div class="topic-content">
                    <div class="topic-user left">
                        <a href="<?php echo $thread['user_url']; ?>">
                            <img src="<?php echo $thread['user_avatar_url']; ?>" class="avatar" alt="<?php echo $thread['username']; ?>" title="<?php echo $thread['username']; ?>">
                            <strong><?php echo $thread['username']; ?></strong>
                            <small><?php echo $thread['create_date_fmt']; ?></small>
                        </a>
                    </div>
                    <div class="topic-message thread_post" id="thread_post" pid="<?php echo $thread['firstpid']; ?>">
                        <h1 class="nospace subject breakall bold" pid="<?php echo $first['pid']; ?>"><?php echo $thread['subject']; ?></h1>
                        <?php echo $first['message']; ?>
                    </div>
                    <div class="topic-actions">
                        <span class="web-icon icon-reply posts <?php echo $thread['posts_class']; ?>" id="posts" title="回复"> <?php echo $thread['posts']; ?></span>
                        <span class="icon-heart" title="喜欢">
                            <i class="icon agree fa fa-heart" tabindex="0" role="button"></i>
                            <i class="icon agreed fa fa-heart liked" title="取消喜欢" style="display: none;" tabindex="0" role="button"></i>
                            <a href="javascript:;" class="ajax dialog nocache icon agrees <?php echo $thread['agrees_class']; ?>" nofollow><span class="likes" title="点击查看喜欢的人"> <?php echo $first['agrees']; ?></span></a>
                        </span>
                        <?php if($allowupdate || $first['allowupdate']) { ?>
                        <a class="right nocache f20 ml15" href="post-update-<?php echo $first['pid']; ?>.htm" title="编辑"><i class="fa fa-edit"></i></a>
                        <?php } ?>
                        <?php if($allowdelete || $first['allowdelete']) { ?>
                        <a class="right delete f20" href="post-delete-<?php echo $first['pid']; ?>.htm" title="删除"><i class="fa fa-trash-o"></i></a>
                    　  <?php } ?>
                    </div>
<?php
  $agreelist = post_agree_find_by_pid($first['pid'], 1, 20);
?>
<?php if($agreelist) { ?>
<div class="topic-info">
    <?php foreach ($agreelist as $agree) { ?>
    <a href="user-<?php echo $agree['uid']; ?>.htm" target="_blank" nofollow>
        <img class="lazyload" data-src="<?php echo $agree['avatar_url']; ?>" title="<?php echo $agree['username']; ?>" width="32" height="32">
    </a>
    <?php } ?>
</div>
<?php } else {?>
<div class="topic-info">暂无人喜欢本帖</div>
<?php } ?>
                </div>
            </div>
        </div>

        <ol class="reply-items"  id="postlist">
        <?php include './pc/view/post_list_body.inc.htm';?>
        </ol>

        <div class="reply-form" data-offset-fixed="10" id="post_create_dl" style="width: 99.8%;">
            <div class="reply-inner clearfix">
                <form id="quick_post_form" action="post-create-<?php echo $tid; ?>-quick.htm" method="post">
                    <textarea class="input-body left" name="message"></textarea>
                    <!-- <div class="post-button-left">
                        <a href="post-create-<?php echo $tid; ?>.htm" target="_blank">编辑器</a>
                    </div> -->
                    <div class="post-button-right">
                        <a class="Button mr15 b-bjq" href="post-create-<?php echo $tid; ?>.htm">编辑器</a>
                        <button class="Button Button--primary" type="submit" loading-text="正在提交...">
                            <span class="submit-button-text">留言</span>
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <div class="stream-footer">
            <div class="stream-end-inner">
                <button class="Button win-back">已加载全部回复，点击返回</button>
            </div>
        </div>
    </div>
    <div class="dashboard">

        <?php if(empty($gid)) { ?>

        <div class="mini-profile">
            <div class="profile-summary">
                <div class="profile-content">
                    <img src="<?php echo $user['avatar_url']; ?>">
                    <b>游客</b>
                    <small>登录后才能发帖哦~</small>
                </div>
            </div>
            <div class="profile-bottom">
                <div class="user-intro">
                    <div class="signin-wrapper">
                        <form class="signin" method="POST" id="login_form" action="user-login.htm">
                            <fieldset>
                                <div class="field">
                                    <input class="form-control" type="text" maxlength="26" name="account" placeholder="邮件地址或昵称">
                                </div>
                                <div class="field">
                                    <input class="form-control" type="password" maxlength="16" name="password" placeholder="密码">
                                </div>
                            </fieldset>
                            <div class="clearfix">
                                <button type="submit" class="Button Button--primary" loading-text="正在登录...">
                                    登录
                                </button>
                                <?php if($conf['user_find_pw_on']) { ?>
                                <a class="forgot f14" href="user-findpw.htm">忘记密码？</a>
                                <?php } ?>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <?php } else { ?>

        <div class="mini-profile">
            <div class="profile-summary">
                <a href="my.htm">
                    <div class="profile-content">
                        <img src="<?php echo $user['avatar_url']; ?>">
                        <b><?php echo $user['username']; ?></b>
                        <small>第 <em><?php echo $user['uid']; ?></em> 位会员</small>
                    </div>
                </a>
            </div>
            <div class="profile-bottom">
                <div class="user-intro">
                    签名处，预留~
                </div>
            </div>
            <div class="profile-bottom">
                <a href="#" class="notify-count">
                    <strong><?php echo $user['threads']; ?></strong>主题
                </a>
                <a href="#" class="favorite-count">
                    <strong><?php echo $user['posts']; ?></strong>帖子
                </a>
                <a href="#" class="balance-count">
                    <strong><?php echo $user['myagrees']; ?></strong>喜欢
                </a>
            </div>
            <div class="profile-bottom">
                <a href="my.htm" class="notify-count">
                    <i class="fa fa-tachometer"></i>设置
                </a>
                <?php if($gid == 1) { ?>
                <a href="admin/" class="favorite-count">
                    <i class="fa fa-cog"></i>管理
                </a>
                <?php } ?>
                <a href="user-logout.htm" class="balance-count">
                    <i class="fa fa-power-off"></i>退出
                </a>
            </div>
        </div>

        <?php } ?>

        <div class="text-list fixed" style="width:290px;">
            <div class="text-inner">
                <div class="text-module-header">
                    <h3>作者帖子</h3>
                </div>
                <ul class="text-items">
                <? $userthreadlist = mythread_find_by_uid($thread['uid'], 1, 6); ?>
                    <?php foreach ($userthreadlist as $userthread) { ?>
                    <li><a href="<?=$userthread['url']?>" title="<?=$userthread['subject']?>"> · <?php echo $userthread['subject']; ?></a></li>
                    <?php } ?>
                </ul>
            </div>
        </div>

        <?php include "./pc/view/copyright.htm"; ?>

    </div>
    <div class="clear"></div>
</div>

<script id="script_data">
var new_thread_days = <?php echo $conf['new_thread_days']; ?>;
var allowpost = <?php echo $allowpost; ?>;
var tid = <?php echo $tid; ?>;
var thread = <?php echo xn_json_encode($thread); ?>;
</script>
<script src="xiunoui/jquery-1.11.1.min.js"></script>
<script>
    var jform = $('#login_form');
    var jaccount = jform.find('input[name="account"]').focus();
    var jpassword = jform.find('input[name="password"]');
    var jsubmit = jform.find('button[type="submit"]');
    jform.off('submit').on('submit', function() {
    //jsubmit.off('click').on('click', function() {
        if(!jaccount.val()) {
            jaccount.popover('请输入 Email').focus();
            return false;
        } else if(!jpassword.val()) {
            jpassword.popover('请输入密码').focus();
            return false;
        }

        var postdata = "account="+jaccount.val()+"&password="+$.md5(jpassword.val());
        jsubmit.button('loading');
        $.xpost(jform.attr('action'), postdata, function(code, message) {
            if(code == 0) {
                jsubmit.button('登录成功');
                //$.pdata('user', user);
                $.pdata('myagreelist', message.myagreelist);
                // 服务端已经设置了 cookie
                //$.cookie('bbs_token', message.token);
                setTimeout(function() {window.location='./';}, 1000);
            } else if(code > 0) {
                if(code == 1) jaccount.popover(message).focus();
                if(code == 2) jpassword.popover(message).focus();
                jsubmit.button('reset');
            } else if(code < 0) {
                alert(message);
                jsubmit.button('reset');
            }
        });
        return false;
    });
</script>
<?php include "./pc/view/footer.inc.htm"; ?>

<script>
render_threadlist();
post_list_script(fid);
forumlist_active(fid);
document_scroll_top();
</script>